package com.xx.redBook.controller;

import com.xx.common.core.controller.BaseController;
import com.xx.common.core.domain.AjaxResult;
import com.xx.common.core.page.TableDataInfo;
import com.xx.common.utils.poi.ExcelUtil;
import com.xx.redBook.domain.RedBookAccount;
import com.xx.redBook.service.IRedBookAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 哔哩账号Controller
 *
 * @author ruoyi
 * @date 2024-09-28
 */
@RestController
@RequestMapping("/redBook/account")
public class RedBookAccountController extends BaseController
{
    @Autowired
    private IRedBookAccountService redBookAccountService;

    /**
     * 查询bili账户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RedBookAccount redBookAccount)
    {
        startPage();
        List<RedBookAccount> list = redBookAccountService.selectRedBookAccountList(redBookAccount);
        return getDataTable(list);
    }

    /**
     * 获取哔哩账号
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(redBookAccountService.selectRedBookAccountById(id));
    }

    /**
     * 新增哔哩账号
     */
    @PostMapping
    public AjaxResult add(@RequestBody RedBookAccount redBookAccount)
    {
        return toAjax(redBookAccountService.insertRedBookAccount(redBookAccount));
    }

    /**
     * 修改哔哩账号
     */
    @PutMapping
    public AjaxResult edit(@RequestBody RedBookAccount redBookAccount)
    {
        return toAjax(redBookAccountService.updateRedBookAccount(redBookAccount));
    }

    /**
     * 删除哔哩账号
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(redBookAccountService.deleteRedBookAccountByIds(ids));
    }

    /**
     * 查询哔哩账号在线状态
     */
    @GetMapping("/checkRedBookAccount")
    public AjaxResult checkRedBookAccount()
    {
        return success(redBookAccountService.checkRedBookAccount());
    }

    /**
     * 下载导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<RedBookAccount> util = new ExcelUtil<RedBookAccount>(RedBookAccount.class);
        util.importTemplateExcel(response, "用户数据");
    }

    /**
     * 导入用户数据
     */
    @PostMapping("/importRedBookAccount")
    public AjaxResult importRedBookAccount(MultipartFile file)
    {
        return success(redBookAccountService.importRedBookAccount(file));
    }
}
